#ifndef IMAGE_HPP
#define IMAGE_HPP

#include <main.hpp>

#define ROAD_WIDTH (0.45)
#define AT(image, x, y) image.at<uint32_t>(y, x)
#define AT_CLIP(img, x, y) AT(img, ILimit(x, 0, img.cols - 1), ILimit(y, 0, img.rows - 1))

// 颜色定义
static const Scalar RED{0, 0, 255};
static const Scalar BLUE{255, 0, 0};
static const Scalar GREEN{0, 255, 0};
static const Scalar PURPLE{255, 0, 255};
static const Scalar YELLOW(0, 255, 255);

struct CrossPoints
{
    int leftUp = 0;
    int rightUp = 0;
    int leftDown = 0;
    int rightDown = 0;
    bool foundCross = false;
};

extern CrossPoints crossPoints;

// 类型定义
using EdgePointsMap = map<int, pair<Point, Point>>;

// 判断点是否在图像范围内
bool isPointValid(const Point &pt, const Mat &img);
// 计算角度
double calculateAngle(const Point &pt1, const Point &pt2);
// 查找边缘起始点
Point findEdgeStartPoint(const Mat &binaryImg, bool isLeftEdge, int lastRow);
// 逆透视
Mat applyPerspectiveTransform(const Mat &src);
// 八邻域
void traceEdge(const Mat &binaryImg, Mat &colorImg, const Point &startPoint, const Scalar &color, int maxPoints, bool isLeftEdge, EdgePointsMap &edgePoints);
// 自适应阈值二值化（大津法）
uint8_t otsuThreshold(const Mat &image);
// 自适应阈值二值化
void adaptive_threshold(Mat &image1, Mat &image2, int block_size, int down_value, uint8_t low_value, uint8_t high_value);
// 寻找max白色列
int findWhiteColumn(Mat &img);
// 寻找最短白色列
int findShortestWhiteColumn(Mat &img);
// 停车保护
int isParking(Mat &img);
// 弯道检测
int iswandao(int& wc, int& lastwc);

int getLongestWhiteColumnIndex(Mat &img);

int countWhitePixelsInColumn(Mat &img, int col);

int zebra(Mat& img);

int changerate(float& y,float& pry);













#endif //IMAGE_HPP
